package com.vehicle.controller;

import com.vehicle.biz.CameraBiz;
import com.vehicle.domains.vo.BasePage;
import com.vehicle.domains.vo.Result;
import com.vehicle.domains.vo.req.camera.*;
import com.vehicle.domains.vo.res.camera.CameraRes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/camera") // 与其他接口路径规范一致，前缀为/api/camera
@Slf4j
@Tag(name = "CameraController", description = "相机设备管理相关接口")
public class CameraController {

    @Resource
    private CameraBiz cameraBiz;

    @PostMapping("/add")
    @Operation(description = "新增相机设备接口")
    public Result<Void> addCamera(@RequestBody @Valid AddCameraReq req) {
        cameraBiz.addCamera(req);
        return Result.success();
    }

    @PostMapping("/update")
    @Operation(description = "更新相机设备接口")
    public Result<Void> updateCamera(@RequestBody @Valid UpdateCameraReq req) {
        cameraBiz.updateCamera(req);
        return Result.success();
    }

    @PostMapping("/delete")
    @Operation(description = "删除单个相机设备接口")
    public Result<Void> deleteCamera(
            @Parameter(schema = @Schema(name = "id", description = "相机设备ID"))
            @RequestParam Long id) {
        cameraBiz.deleteCamera(id);
        return Result.success();
    }


    @PostMapping("/getById")
    @Operation(description = "查询相机设备详情接口")
    public Result<CameraRes> getCameraById(
            @Parameter(schema = @Schema(name = "id", description = "相机设备ID"))
            @RequestParam Long id) {
        return Result.success(cameraBiz.getCameraById(id));
    }

    @PostMapping("/list")
    @Operation(description = "分页查询相机设备列表接口")
    public Result<BasePage<CameraRes>> list(@RequestBody @Valid CameraListReq req) {
        return Result.success(cameraBiz.list(req));
    }

    @PostMapping("/bindCamera")
    @Operation(description = "绑定相机设备接口")
    public Result<Void> bindCamera(@RequestBody @Valid BindCameraReq req) {
        cameraBiz.bindCamera(req);
        return Result.success();
    }

    @PostMapping("/unbindCamera")
    @Operation(description = "解绑相机设备接口")
    public Result<Void> unbindCamera(@RequestBody @Valid UnBindCameraReq req) {
        cameraBiz.unbindCamera(req);
        return Result.success();
    }
}
